package ua.kpi_java_training.morochenets.module2;

/**
 * Class for output statistical results
 *
 * @author Ari100tell
 * @data: 01.06.13
 * @time: 16:08
 */
public class StatisticalResults {
    private int numberOfPredators = 0;
    private int numberOfPrey = 0;
    private int width;
    private int length;

    public StatisticalResults(int width, int length) {

        this.width = width;
        this.length = length;
    }

    /**
     * @param placesForLife Array containing information about fish in the pool
     * @param typeOfFish    Type of fish that you want to count the number of
     * @return Number of fish species specific
     */

    public int counting(int[][] placesForLife, String typeOfFish) {
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < length; j++) {
                if (placesForLife[i][j] == -1) {
                    numberOfPredators++;
                } else if (placesForLife[i][j] == 1) {
                    numberOfPrey++;
                }
            }

        }
        return definitionType(numberOfPredators, numberOfPrey, typeOfFish);
    }


    private int definitionType(int numberOfPredators, int numberOfPrey, String typeOfFish) {
        if (typeOfFish == "Prey") {
            return numberOfPrey;
        } else if (typeOfFish == "Predator") {
            return numberOfPredators;
        } else return 0;
    }

    public void output(String hint, int value) {
        System.out.println();
        System.out.println(hint);
        System.out.println(value);
    }

    public void outputAll(int[][] placesForLife) {
        output("Number of predators in the pool", counting(placesForLife, "Predator"));
        output("Number of prey in the pool", counting(placesForLife, "Prey"));
    }


}
